﻿@model IEnumerable<HotelRegistrationSystem.Models.RoomHotelModel>

@{
    ViewBag.Title = "ViewRooms";
}

@Styles.Render("~/Content/themes/start/css")

<h2>View Hotel Rooms</h2>

<table style="width: 100%">
    <tr>
        <th style="width: 200px">
            @Html.DisplayNameFor(model => model.Name)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Price)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Desciption)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.RoomTypeId)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.BedCount)
        </th>
        <th></th>
    </tr>

    @foreach (var item in Model)
    {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.Name)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Price)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Desciption)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.RoomType.Type)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.BedCount)
            </td>
            <td>
                @Html.ActionLink("Edit", "EditRoom", new { roomId = item.RoomId }) |
               @Html.ActionLink("Delete", "DeleteRoom", new { roomId = item.RoomId }, new { @class = "deleteLink" } ) | 
                @Html.ActionLink("Make reservation", "OwnerBooking", new { hotelId = item.HotelId, roomId = item.RoomId}) | 
                @Html.ActionLink("Reservations", "RoomReservations", new {roomId = item.RoomId})
            </td>
        </tr>
    }

</table>

<div id="dialog-confirm" title="Delete?" > 
    <p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>Are you sure you want to delete this room?</p> 
</div>

@Html.ActionLink("Create a room", "CreateRoom", new { hotelId = Model.First().HotelId }, new { @class = "button small radius"})
@Html.ActionLink("Back", "Edit", new { hotelId = Model.First().HotelId }, new { @class = "button small radius"})

@section Scripts {
    @Scripts.Render("~/bundles/jqueryui")

    <script>
        $(function () {
            $("#dialog-confirm").dialog({
                autoOpen: false,
                modal: true,
                resizable: false,
                height: 180,
            });

            $(".deleteLink").click(function (e) {
                e.preventDefault();
                var targetUrl = $(this).attr("href");

                $("#dialog-confirm").dialog({
                buttons: {
                        "Confirm": function () {
                            window.location.href = targetUrl;
                    },
                        "Cancel": function () {
                        $(this).dialog("close");
                    }
                }
            });

                $("#dialog-confirm").dialog("open");
            });
        });
    </script>
}